/*
 * Copyright 1999-2101 Alibaba Group.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 	http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package cn.com.gridinfo.sooc.utils;

import android.content.Context;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import org.w3c.dom.Text;

import cn.com.gridinfo.sooc.R;
import cn.com.gridinfo.sooc.SoocApplication;


/**
 * 
 * @author zhe.yangz
 */
public class MessageUtils {
	public static void showLongToast(Context context, int res) {
		try {
			Toast.makeText(SoocApplication.getContext(), res, Toast.LENGTH_LONG).show();
		} catch (Exception e) {
		}

	}

	public static void showShortToast(Context context, int res) {
		try {
			Toast.makeText(SoocApplication.getContext(), res, Toast.LENGTH_SHORT).show();
		} catch (Exception e) {
		}

	}

	public static void showLongToast(Context context, String text) {
		try {
			if (!text.equals(""))
				Toast.makeText(SoocApplication.getContext(), text, Toast.LENGTH_LONG).show();
		} catch (Exception e) {
		}

	}

	public static void showShortToast(Context context, String text) {
		try {
			if (!text.equals(""))
				Toast.makeText(SoocApplication.getContext(), text, Toast.LENGTH_SHORT).show();
		} catch (Exception e) {
		}

	}

	public static void showImageLongToast(Context context, String text){
		try {

			if(!text.equals("")){
			Toast toast = Toast.makeText(SoocApplication.getContext(),
					text, Toast.LENGTH_LONG);
			toast.setGravity(Gravity.CENTER, 0, 0);
			LinearLayout toastView = (LinearLayout) toast.getView();
			ImageView imageCodeProject = new ImageView(SoocApplication.getContext());
			imageCodeProject.setImageResource(R.mipmap.ic_show_error);
			toastView.addView(imageCodeProject, 0);
			toast.show();}

		}catch (Exception e){

		}

	}

	/**
	 * 错误提示信息
	 * @param context
	 * @param text
     */
	public static void showImageShortToast(Context context, String text){
		try {
			if(!text.equals("")){
				LayoutInflater	inflater = LayoutInflater.from(SoocApplication.getContext());
				View toastView = inflater.inflate(R.layout.toast_hint, null);
				TextView hintInfo = (TextView)toastView.findViewById(R.id.toast_txt);
				hintInfo.setText(text);
				ImageView image =  (ImageView)toastView.findViewById(R.id.toast_ico);
				image.setImageResource(R.mipmap.ic_show_error);
				Toast toast = Toast.makeText(SoocApplication.getContext(),
						text, Toast.LENGTH_SHORT);
				toast.setGravity(Gravity.CENTER, 0, 0);

				toast.setView(toastView);
				toast.show();
			}

		}catch (Exception e){

		}

	}

	/**
	 * 正确提示
	 * @param context
	 * @param text
     */
	public static void showRightImageShortToast(Context context, String text){
		try {
			if(!text.equals("")){
				LayoutInflater	inflater = LayoutInflater.from(SoocApplication.getContext());
				View toastView = inflater.inflate(R.layout.toast_hint, null);
				TextView hintInfo = (TextView)toastView.findViewById(R.id.toast_txt);
				hintInfo.setText(text);
				ImageView image =  (ImageView)toastView.findViewById(R.id.toast_ico);
				image.setImageResource(R.mipmap.ic_show_right);
				Toast toast = Toast.makeText(SoocApplication.getContext(),
						text, Toast.LENGTH_SHORT);
				toast.setGravity(Gravity.CENTER, 0, 0);

				toast.setView(toastView);
				toast.show();
			}

		}catch (Exception e){

		}

	}

}
